package com.vcourse.oauth2.component;

import com.vcourse.commons.result.R;
import com.vcourse.commons.result.ResultCodeEnum;
import com.vcourse.commons.utils.ResponseUtil;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Zengsh123
 * @date 2020-06-17 15:07
 *
 * 当访问接口没有权限时，自定义的返回结果
 */

public class RestfulAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request,
                       HttpServletResponse response,
                       AccessDeniedException e) {
        ResponseUtil.out(response, R.setResult(ResultCodeEnum.LOGIN_ACL));
    }
}
